package com.baiduspring.elasticsearch.operation;

import lombok.AllArgsConstructor;
import lombok.Getter;
import lombok.NoArgsConstructor;
import lombok.Setter;

import java.util.List;
import java.util.Objects;

/**
 * 输出查询结果值
 *
 * @param <T> 泛型参数
 * @author xiongyan
 */
@NoArgsConstructor
@AllArgsConstructor
@Getter
@Setter
public class QueryResultsOutput<T> {
    /**
     * 返回的数据集中
     */
    private List<T> results;
    /**
     * 返回单一数据结果
     */
    private T result;
    /**
     * 总条数
     */
    private long total;
    /**
     * 总页数
     */
    private long totalPages;

    /**
     * 计算总页数并记录总条数
     */
    public void totalPages(long total, Integer pageSize) {
        this.total = total;
        if (Objects.nonNull(pageSize)) {
            this.totalPages = total % pageSize == 0 ? total / pageSize : total / pageSize + 1;
        }
    }
}
